package com.tyy.springbootmysql.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tyy.springbootmysql.entity.UserInfo;
import com.tyy.springbootmysql.mapper.UserInfoMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;


// import static org.apache.logging.log4j.message.MapMessage.MapFormat.JSON;


@Service
@Slf4j
public class UserInfoServiceAsync extends ServiceImpl<UserInfoMapper, UserInfo> {
    @Autowired
    private UserInfoMapper userInfoMapper;

    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public boolean updateUserInfo(UserInfo userInfo) {
        UserInfo userInfo1  = new UserInfo();
        // userInfo1.setUserId(1L);
        userInfo1.setRealName("update11");
        userInfo1.setPhone("18779999999");
        userInfo1.setPassword("123456");
        boolean result = userInfoMapper.insert(userInfo1) > 0;
        // boolean result = userInfoMapper.updateById(userInfo1) > 0;
        int i = 1 / 0;
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        log.info("updateUserInfo: {}", result);
        return result;
    }


}
